<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<title>发表讨论</title>
		<link rel="stylesheet" type="text/css" href="../../css/weui.css" />
		<link rel="stylesheet" href="../../css/mui.min.css" />
		<link rel="stylesheet" href="../../css/base.css"/>
		<style>
			body {
				background-color: rgba(100,100,100,0.6);
			}
			/*.modbox,.modbl,.modbc,.modbr{
			 filter:alpha(opacity=80);
			 -moz-opacity:0.8;
			 width:auto !important;
			 width:100%
			 }*/
			.setCenterDiv {
				position: absolute;
				background-color: #fff;
				margin-bottom: 10px;
				margin-left: 20px;
			}
			.jiangeDiv {
				height: 10px;
			}
			/*.navDiv{
			 background-color: #28292D;
			 height: 44px;
			 display: -webkit-flex;
			 display: flex;
			 align-items: center;
			 justify-content:center;
			 justify-content: space-between;
			 }*/
			.inputTextareaDiv {
				margin-top: 10px;
			}
			#editNoteSpan {
				color: white;
				font-size: 16px;
			}
			#commitBtn {
				margin-right: 10px;
				color: #0CB800;
				visibility: hidden;
			}
			/*#returnBtn{
			 color: white;
			 margin-left: 10px;
			 }*/
			.tdImgSet img {
				width: 30px;
				height: 30px;
			}
			.dafenDiv {
				margin-top: 10px;
				width: 100%;
				clear: both;
				font-weight: lighter;
				margin-left: 60px;
			}
			#dafenSpan {
				float: left;
				display: block;
				line-height: 40px;
				font-size: 20px;
			}
			table {
				padding-left: 20px;
			}
			td {
			}
			#successA {
				/*position: relative;*/
			}
			#commentTextarea {
				height: 100px;
			}
			#alertDiv {
				display: none;
			}
			#fabiaoBtn {
				margin-top: 20px;
				width: 80%;
			}
			:focus {
				outline: 0;
			}
			* {
				-webkit-tap-highlight-color: rgba(255,255,255,0);
			}
			input, textarea {
				-webkit-appearance: none;
				border-radius: 0;
			}
			.mui-btn-block {
				margin: 0 auto;
				margin-top: 10px;
				margin-bottom: 16px;
				width: 80%;
				padding: 8px 0;
			}
		</style>
	</head>
	<body>
		<div class="showSelectListDiv">
			<div class="setCenterDiv" style="border-radius:10px;">
				<div class="writeReport ">
					<div class="bgwhite top_2 " style="border-radius:10px;">
						<span class=" mui-icon mui-icon-closeempty right right_15 top_5" onclick="closeFrame()"></span>
						<p class="title titlepos">
							内容
						</p>
						<div class="textare_div">
							<textarea class="textarea_t " id="summary"  placeholder="字数最多300字" autofocus="autofocus"></textarea>
						</div>
						<div >
							<button id="sumbit_bt" type="button" class="    mui-btn  mui-btn-warning mui-btn-block  " onclick="addDiscus()" >
								提交
							</button>
						</div>
					</div>
				</div>
			</div>
		</div>
	</body>
	<script type="text/javascript" src="../../script/jquery.min.js"></script>
	<script type="text/javascript" src="../../script/util.js"></script>
	<script src="../../script/common.js"></script>
	<script type="text/javascript" src="../../script/databaseOperation.js"></script>
	<script type="text/javascript" src="../../script/url.js"></script>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/MD5.js"></script>
	<script type="text/javascript" src="../../script/requestTool.js"></script>
	<script type="text/javascript" src="../../script/utils.js"></script>
	<script type="text/javascript">
		//		var url = 'http://cfnet.org.cn/index2.php?m=android&c=Freecourse&a=adddiscuss';
		var pid = "";
		// 计划id
		var cid = "";
		//课程id
		var chapterid = "";
		//章节id
		var title = "";
		apiready = function() {
			ChangeFrame();
			var pageParam = api.pageParam;
			pid = pageParam.pid;
			cid = pageParam.cid;
			chapterid = pageParam.chapterid;
			title = pageParam.title;
			fid = pageParam.fid;
			//检测键盘弹出事件
			SoftKeyboard();
			//安卓手机系统返回键事件
			keyback();
		}
		function ChangeFrame() {
			$('.showSelectListDiv').css('height', api.frameHeight);
			var textWidth = api.frameWidth - 80;
			$api.css($api.dom('textarea'), 'width:' + textWidth + 'px;');
			// 设置居中
			$api.css($api.dom('.setCenterDiv'), 'top: ' + (api.frameHeight - 260) / 2 + 'px;width: ' + (api.frameWidth - 40) + 'px;');
		}

		//安卓手机系统返回键事件
		function keyback() {
			//安卓手机系统返回键事件
			api.addEventListener({
				name : 'keyback'
			}, function(ret, err) {
				api.closeFrame({
					name : 'MoccCourse_AddDiscus'
				});
			});
		}

		function SoftKeyboard() {
			var winHeight = $(window).height();
			//检测键盘弹出事件
			$(window).resize(function() {
				var thisHeight = $(this).height();
				if (winHeight - thisHeight > 50) {
					$api.css($api.dom('.setCenterDiv'), 'top: ' + (api.frameHeight - 120) / 2 + 'px;width: ' + (api.frameWidth - 40) + 'px;');
				} else {
					$api.css($api.dom('.setCenterDiv'), 'top: ' + (api.frameHeight - 260) / 2 + 'px;width: ' + (api.frameWidth - 40) + 'px;');
				}
			});
		}

		//提交新的课程讨论
		function addDiscus() {
			var message;
			var reg = /\s/;
			var newcontent = $('#summary').val().trim();
			var param = {
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjxid'),
				pid : pid,
				cid : cid,
				vid : chapterid,
				title : title,
				content : newcontent,
				fid : 0,
			};
			if (newcontent == null || newcontent == "") {
				ShowToast("输入不能为空");
			} else if (newcontent.length > 300) {
				ShowToast("字数不能超过300字");
			} else {
				showProgress();
				cfnetppPOST(url_AdddiscussUrl, param, false, function(data, status) {
					hideProgress();
					if ($api.getStorage('cfnetSelectType') == 0) {//学生身份
						SendBusinessOperationsLogNotifi('讨论列表页', '020', param, param, '', data, 'Mocc课程讨论章节学生添加讨论', '020-01')
					} else if ($api.getStorage('cfnetSelectType') == 1) {//老师身份
						SendBusinessOperationsLogNotifi('讨论列表页', '020', param, param, '', data, 'Mocc课程讨论章节老师添加讨论', '020-06')
					}
					if (status == 'success') {
						if (data.status == true) {
							ShowToast('提交讨论成功');
							sendNotifi();
							closeFrame();
						} else {
							api.toast({
								msg : '提交讨论失败',
								duration : 2000,
								location : 'bottom'
							});
						}
					} else {
						api.toast({
							msg : '网络异常',
							duration : 2000,
							location : 'bottom'
						});
					}
				});
			}
		}

		function closeFrame() {
			api.closeFrame({
				name : 'MoccCourse_AddDiscus'
			});
		}

		function sendNotifi() {
			api.sendEvent({
				name : 'RefreshMoccAddDiscusListNotifi'
			});
			api.sendEvent({
				name : 'freeCourseRecordNotifi',
				extra : {
					uid : $api.getStorage('cfnetppuid'),
					jid : $api.getStorage('cfnetppjxid'),
					pid : pid,
					cid : cid,
					vid : chapterid,
				}
			});
		}
	</script>
</html>
